package com.android.taobao.api;

import java.util.List;

import com.android.taobao.client.CommonClient;
import com.taobao.api.TaobaoApiException;
import com.taobao.api.TaobaoJsonRestClient;
import com.taobao.api.model.ItemCat;
import com.taobao.api.model.ItemCatsGetRequest;
import com.taobao.api.model.ItemCatsResponse;

public class TaobaoItemCatsGet {
	public static void main(String args[]) throws TaobaoApiException {
		TaobaoJsonRestClient client = CommonClient.getInstance();
		ItemCatsGetRequest req = new ItemCatsGetRequest();
		req.setFields("cid,name,status,sort_order,parent_cid,is_parent");
		req.setParentCid("21");
		ItemCatsResponse rsp = client.itemCatsGet(req);
		List<ItemCat> cats = rsp.getItemCats();
		for (ItemCat cat : cats) {
			System.out.println("cid: " + cat.getCid());
			System.out.println("类目名称: " + cat.getName());
			System.out.println("父类目cid: " + cat.getParentCid());
			System.out.println("是否包含子类目: " + cat.getIsParent());
		}
	}

	public static List<ItemCat> getItemCats() throws TaobaoApiException {
		TaobaoJsonRestClient client = CommonClient.getInstance();
		ItemCatsGetRequest req = new ItemCatsGetRequest();
		req.setFields("cid,name,status,sort_order,parent_cid,is_parent");
		req.setParentCid("0");
		ItemCatsResponse rsp = client.itemCatsGet(req);
		List<ItemCat> cats = rsp.getItemCats();
		return cats;
	}
}